<html>
<head><meta charset="utf-8"><title>missing safe abstractions · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html">missing safe abstractions</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="194489443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489443">(Apr 17 2020 at 19:32)</a>:</h4>
<p><span class="user-mention" data-user-id="127617">@Shnatsel</span> I'd be very interested in doing a kind of "review" of the patterns you're seeing that people have to "roll their own"</p>



<a name="194489452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489452">(Apr 17 2020 at 19:32)</a>:</h4>
<p>in particular ones that may have implications for language design</p>



<a name="194489485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489485">(Apr 17 2020 at 19:32)</a>:</h4>
<p>I'm also quite interested, in general, in trying to find ways to make writing correct, efficient unsafe code more ergonomic.</p>



<a name="194489517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489517">(Apr 17 2020 at 19:33)</a>:</h4>
<p>It might be useful to have a kind of joint lang/secure-code brainstorming session to share thoughts and ideas?</p>



<a name="194489532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489532">(Apr 17 2020 at 19:33)</a>:</h4>
<p>Heck we could do a virtual workshop :)</p>



<a name="194489538"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489538" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489538">(Apr 17 2020 at 19:33)</a>:</h4>
<p>/me gettin' crazy</p>



<a name="194489744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194489744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194489744">(Apr 17 2020 at 19:35)</a>:</h4>
<p>Cool, I guess I need to sit down and make a list then! Or better, enable other people to make it themselves.<br>
One was coming up so frequently I made an RFC to fix it: <a href="https://github.com/rust-lang/rfcs/pull/2714" title="https://github.com/rust-lang/rfcs/pull/2714">https://github.com/rust-lang/rfcs/pull/2714</a></p>



<a name="194490269"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490269" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490269">(Apr 17 2020 at 19:39)</a>:</h4>
<p>ah yes I remember that now</p>



<a name="194490317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490317">(Apr 17 2020 at 19:40)</a>:</h4>
<p>I'd like to see that move forward.</p>



<a name="194490318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490318">(Apr 17 2020 at 19:40)</a>:</h4>
<p>interesting.</p>



<a name="194490376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490376">(Apr 17 2020 at 19:40)</a>:</h4>
<p>I was just saying to <span class="user-mention" data-user-id="239881">@Josh Triplett</span> randomly that I think there is a lot of value in enabling people to write "things that used to need unsafe" but without unsafe</p>



<a name="194490400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490400">(Apr 17 2020 at 19:41)</a>:</h4>
<p>this is a point that <span class="user-mention" data-user-id="224872">@Ryan Levick</span> impressed upon me when we were discussing <a class="stream" data-stream-id="216762" href="/#narrow/stream/216762-project-safe-transmute">#project-safe-transmute</a></p>



<a name="194490423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490423">(Apr 17 2020 at 19:41)</a>:</h4>
<p>but I think that this is <em>going</em> to ultimately mean 80% abstractions that can't cover all the cases</p>



<a name="194490522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490522">(Apr 17 2020 at 19:42)</a>:</h4>
<p>I guess that this method fits in that category</p>



<a name="194490616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490616">(Apr 17 2020 at 19:43)</a>:</h4>
<p>Yeah, we can't cover all the cases but we can gradually cover more and more of them. <code>from_le_bytes</code> and friends on integers made a huge difference, as did TryFrom stabilization because it enabled feeding subslices to <code>from_*_bytes</code></p>



<a name="194490679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490679">(Apr 17 2020 at 19:43)</a>:</h4>
<p>Yeah. Though that reminds me...</p>



<a name="194490695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490695">(Apr 17 2020 at 19:44)</a>:</h4>
<p>I would really love to have a trait for <code>to_le_bytes</code>.</p>



<a name="194490762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490762">(Apr 17 2020 at 19:44)</a>:</h4>
<p>Another thing that's actually landing in 1.43 and came out of safety-dance is creating a <code>CString</code> from a <code>Vec&lt;NonZeroU8&gt;</code> without scanning the data twice. This enables constructing a <code>CString</code> from a reader without resorting to <code>unsafe</code> to avoid the rescan.</p>



<a name="194490781"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490781" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490781">(Apr 17 2020 at 19:44)</a>:</h4>
<p>Nice!</p>



<a name="194490805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490805">(Apr 17 2020 at 19:44)</a>:</h4>
<p>The first scan can transmute to note that it's non-zero?</p>



<a name="194490957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490957">(Apr 17 2020 at 19:46)</a>:</h4>
<p>Basically you read bytes from a reader until you reach 0, and since you're checking the bytes one by one anyway you might as well construct a <code>NonZeroU8</code> out of them right away as you put them in a <code>Vec</code>. Then you can get a <code>CString </code>from that <code>Vec</code> without a second scan.</p>



<a name="194490990"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194490990" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194490990">(Apr 17 2020 at 19:46)</a>:</h4>
<p>Given const generics, how hard would it be to specify a trait <code>ToEndianBytes</code> that provides <code>to_le_bytes</code> for a type, returning a slice of <code>u8</code> where the size of the slice depends on the type but it's known to be a slice of <code>u8</code>?</p>



<a name="194491028"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491028" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491028">(Apr 17 2020 at 19:46)</a>:</h4>
<p>Because then I could rewrite my current macro <code>write_le!</code> as a function rather than a macro.</p>



<a name="194491097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491097">(Apr 17 2020 at 19:47)</a>:</h4>
<p>I don't want to write out <code>w.write_all(&amp;(expr).to_le_bytes())?;</code> hundreds of times, so I have a macro wrapping that: <code>write_le!(w, expr)?;</code>.</p>



<a name="194491428"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491428" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491428">(Apr 17 2020 at 19:50)</a>:</h4>
<p>The latest thing I looked at was <code>rand</code>. I've put an assert on lengths before a hot loop so that the compiler would optimize away the bounds checks and <code>get_unchecked()</code> would not be needed. This seems to be a very valuable but little-known trick. I think we should document it somewhere</p>



<a name="194491497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491497">(Apr 17 2020 at 19:51)</a>:</h4>
<p>Nice!</p>



<a name="194491520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491520">(Apr 17 2020 at 19:51)</a>:</h4>
<p>Where did the value come from right before the loop, that it had a bound but the compiler didn't know that?</p>



<a name="194491600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491600">(Apr 17 2020 at 19:52)</a>:</h4>
<p>A surprisingly unsafe-heavy crate is <code>log</code>. It tries to have an atomic integer that actually represents an enum, and conversions to and from that enum are necessarily unsafe and unchecked because they're on the hot path for logging, and they don't want to have unwinding code in there. I think it also hand-rolls a <code>no_std</code> variant of <code>lazy_static</code> inside the crate.</p>



<a name="194491643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491643">(Apr 17 2020 at 19:52)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> here's the PR: <a href="https://github.com/rust-random/rand/pull/960" title="https://github.com/rust-random/rand/pull/960">https://github.com/rust-random/rand/pull/960</a></p>



<a name="194491864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491864">(Apr 17 2020 at 19:54)</a>:</h4>
<p>Interesting. So, I get why dd is less than 512 (the compiler should really know that the result of <code>% 512</code> will be less than 512), but what makes <code>cc + 15 &lt; 512</code>? How does the code know that?</p>



<a name="194491902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491902">(Apr 17 2020 at 19:54)</a>:</h4>
<p>Oh, I see the assertion right above that, nevermind.</p>



<a name="194491929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491929">(Apr 17 2020 at 19:55)</a>:</h4>
<p>I wonder how hard it would be to get the compiler to do some numerical reasoning like that?</p>



<a name="194491977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194491977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194491977">(Apr 17 2020 at 19:55)</a>:</h4>
<p>GCC is capable of some <em>amazing</em> reasoning about bit patterns in a value; you can hand-write things like byte swaps and rotates, and they'll turn into the corresponding instruction.</p>



<a name="194493148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194493148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194493148">(Apr 17 2020 at 20:04)</a>:</h4>
<p>I probably should dust off <a href="https://github.com/rust-lang/rfcs/pull/2714" title="https://github.com/rust-lang/rfcs/pull/2714">https://github.com/rust-lang/rfcs/pull/2714</a>, I have an implementation of the current proposed design handy but I'm not sure it's the best design anymore. It's the easiest one to explain, but it doesn't really solve the problem in the fastest possible way, so people might still want to hand-roll a custom implementation. And the fastest possible version is harder to explain, even though it's more general</p>



<a name="194494175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194494175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194494175">(Apr 17 2020 at 20:13)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I'll look through safety-dance crates and make an issue on a dedicated repo for every currently unavoidable <code>unsafe</code> I find, then send you a link. That way we can have a clear set of problems and it would make sense to start brainstorming solutions. How's that for a plan?</p>



<a name="194494514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194494514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194494514">(Apr 17 2020 at 20:16)</a>:</h4>
<p>Also I've been replacing a ton of ad-hoc unsafe with variants of <code>u16::from_le_bytes([..2].try_into().unwrap())</code> which is fine, but counter-intuitive. I'm told that const generics might help with the <code>.try_into().unwrap()</code> part.</p>



<a name="194538521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194538521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194538521">(Apr 18 2020 at 10:56)</a>:</h4>
<p><span class="user-mention" data-user-id="127617">@Shnatsel</span> that sounds like a good plan</p>



<a name="194552422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194552422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194552422">(Apr 18 2020 at 16:22)</a>:</h4>
<p>Regarding bounds checks: a quick search through <a href="http://crates.io" title="http://crates.io">crates.io</a> shows that there are currently 10670 invocations of <code>get_unchecked</code> (incl. <code>_mut</code> variant) across 864 crates, and the median number of uses per crate is 3.</p>



<a name="194725389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194725389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194725389">(Apr 20 2020 at 20:02)</a>:</h4>
<p>Wow, that's kind of astounding.</p>



<a name="194725401"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194725401" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194725401">(Apr 20 2020 at 20:02)</a>:</h4>
<p>How many <em>crates</em> use it?</p>



<a name="194746194"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194746194" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194746194">(Apr 20 2020 at 23:39)</a>:</h4>
<p>864 crates</p>



<a name="194830503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194830503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194830503">(Apr 21 2020 at 16:49)</a>:</h4>
<p>oh heh it's... right there in the message</p>



<a name="194830608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194830608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194830608">(Apr 21 2020 at 16:50)</a>:</h4>
<p>OK, so that is "3 uses per crate <strong>that use <code>get_unchecked</code></strong>, not 3 uses per crate on <a href="http://crates.io" title="http://crates.io">crates.io</a> or something...</p>



<a name="194919920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/194919920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Charles Lew <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#194919920">(Apr 22 2020 at 12:05)</a>:</h4>
<p>About safe abstractions. Someone made a nice (but a little outdated since it's in '18) list here:<br>
<a href="https://users.rust-lang.org/t/list-of-crates-that-improves-or-experiments-with-rust-but-may-be-hard-to-find/17806" title="https://users.rust-lang.org/t/list-of-crates-that-improves-or-experiments-with-rust-but-may-be-hard-to-find/17806">https://users.rust-lang.org/t/list-of-crates-that-improves-or-experiments-with-rust-but-may-be-hard-to-find/17806</a></p>



<a name="203790475"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203790475" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203790475">(Jul 14 2020 at 01:25)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> I've put together a list of missing safe abstractions encountered during <a href="https://github.com/rust-secure-code/safety-dance">Safety Dance</a>: <a href="https://hackmd.io/@xmxSgN6MSImJPcY4MOKfjA/rJSKhO9kw/edit">https://hackmd.io/@xmxSgN6MSImJPcY4MOKfjA/rJSKhO9kw/edit</a><br>
It's a little rough and possibly incomplete, but if I keep working on it I'll never release it. I can go in a lot of depth on pretty much every point though, so please ask.<br>
It should also be editable by everyone with a link, feel free to add things there.</p>



<a name="203790564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203790564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203790564">(Jul 14 2020 at 01:27)</a>:</h4>
<p>That's really interesting!</p>



<a name="203790569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203790569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203790569">(Jul 14 2020 at 01:27)</a>:</h4>
<p>I'm wondering if that might make a good subject for a future design meeting.</p>



<a name="203790618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203790618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203790618">(Jul 14 2020 at 01:28)</a>:</h4>
<p>Though probably half of them are libs material rather than lang.</p>



<a name="203790985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203790985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203790985">(Jul 14 2020 at 01:35)</a>:</h4>
<p>hey hey hey Shnatsel you very well know that there's safe explicit SIMD ;P</p>



<a name="203791208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203791208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203791208">(Jul 14 2020 at 01:39)</a>:</h4>
<p>Seeing how people keep trying to build yet another version of it and promptly devolve into something that fits very few actual use cases, I'd say there's really not.<br>
Also you never promoted your other SIMD crate (not <code>wide</code>) so I'm kind of unaware of what it does, I don't even remember the name. Also I'm unaware of its current status.</p>



<a name="203791372"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203791372" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203791372">(Jul 14 2020 at 01:42)</a>:</h4>
<p>Oh it's <a href="https://crates.io/crates/safe_arch"><code>safe_arch</code></a>. Looks cool but nothing uses it. People just seem to avoid explicit SIMD for the time being in general.</p>



<a name="203791571"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203791571" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203791571">(Jul 14 2020 at 01:46)</a>:</h4>
<p><span class="user-mention" data-user-id="224471">@Lokathor</span> this reminds me, we should work on announcements for your crates. <code>bytemuck</code> could use more press.</p>



<a name="203791587"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203791587" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203791587">(Jul 14 2020 at 01:47)</a>:</h4>
<p><code>wide</code> is half baked and should be part of libcore/libstd some day</p>



<a name="203791648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203791648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203791648">(Jul 14 2020 at 01:49)</a>:</h4>
<p>I think it's easier to use than packed_simd, but also made it so i know it super well.</p>
<p>but anyway, there's already an MCP in for SIMD improvements</p>



<a name="203792410"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203792410" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Shnatsel <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203792410">(Jul 14 2020 at 02:08)</a>:</h4>
<p>What's an MCP?</p>



<a name="203792420"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/missing%20safe%20abstractions/near/203792420" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/missing.20safe.20abstractions.html#203792420">(Jul 14 2020 at 02:09)</a>:</h4>
<p>oh uh, a Major Change Proposal, it's the new "pre-RFC" system basically</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>